﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;

namespace FOBTV.Web.FOBTV2011.UserControl
{
    public partial class RegistrationControlCn : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           // txtBirthday.Attributes.Add("readonly", "true");
            if (!IsPostBack)
            {
               //dMemberShip();
            }
        }

        //private void BindMemberShip()
        //{
        //    System.Data.OleDb.OleDbConnection Conn = new System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("..\\..\\DB\\FOBTVweb.mdb"));
        //    string strSql = "select MembershipID,MemberShip from MemberShipType";
        //    FOBTV.Web.MainClass.PageWrapClass pw = new FOBTV.Web.MainClass.PageWrapClass();
        //    pw.Conn = Conn;
        //    pw.FillDropDownList(ddlMemberShipm,strSql);
        //}

        protected void BtnSubmit_Click(object sender, EventArgs e)
        {
            Submit("insert");
        }

        private void Submit(string type)
        {
            System.Data.OleDb.OleDbConnection Conn = new System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("..\\..\\DB\\FOBTVweb.mdb"));
            FOBTV.Web.MainClass.DBClass DBClassTmp = new FOBTV.Web.MainClass.DBClass();
            ArrayList sql = new ArrayList();
            sql.Clear();
            FOBTV.Web.MainClass.User info = new FOBTV.Web.MainClass.User();

            string varPrefix = info.Prefix = this.rblPrefix.SelectedValue;
            string varFirstName = info.FirstName = txtFirstName.Text.Trim();
            string varLastName = info.LastName = "";
             ;
            string varPassport = info.Passport = "";
            string varBusinessTitle = info.BusinessTitle = txtBusinessTitle.Text.Trim();
            string varFullCompanyName = info.FullCompanyName = txtFullCompanyName.Text.Trim();
            string varURL = "";
            string varAddress = info.Address = txtAddress.Text.Trim();
            string varAddress2 = info.Address2 ="";
            string varAddress3 = info.Address3 = "";
            string varPostalCode = info.PostalCode = txtPostalCode.Text.Trim();
            string varCity = "";
            string varState = "";

            string varCountry = "";
            string varMoblie = txtMoblie.Text.Trim();
            string varPhone = txtPhone.Text.Trim();
            string varFax = txtFax.Text.Trim();
            string varEmail = info.Email = txtEmail.Text.Trim();
            string varRegistrationType = "";
            string varMemberShip = ddlMemberShip.SelectedItem.Text.Trim();
            string varMemberShipID = ddlMemberShip.SelectedItem.Value.Trim();
            string varPassword = FOBTV.Web.MainClass.DEncrypt.Encrypt(txtPassword.Text.Trim());
            info.State = 1;
            info.CreatPDFTime = System.DateTime.Now;
            info.Birthday = System.DateTime.Now;
            int varCustomerID = 0;
            string strCustomerID = "";
            MainClass.GetUserInfo userInfoClass = new MainClass.GetUserInfo();
            userInfoClass.Conn = Conn;
            userInfoClass.Email = varEmail;
           
            varCustomerID = DBClassTmp.GetIDInfo("SELECT max(CLng(Right(CustomerID,len(CustomerID)-Instr(1,CustomerID,'V',1)))) FROM CustomerInfo", Conn) + 1;
            strCustomerID = "FOBTV" + varCustomerID.ToString();
            if (!userInfoClass.CheckUserInfoExists())
            {
                sql.Add("INSERT INTO CustomerInfo(CustomerID,Prefix,FirstName,LastName,Birthday,Passport,BusinessTitle,FullCompanyName,URL,Address,Address2,Address3,PostalCode,City,State,Country,Moblie,Phone,Fax,Email,RegistrationType,MemberShip,PasswordInfo,MemberShipID,CreateTime,StatusID,Status)VALUES ('" +
                    strCustomerID + "','" +
                    varPrefix + "','" +
                    varFirstName + "','" +
                    varLastName + "','" +
                    System.DateTime.Now.ToString() + "','" +
                    varPassport + "','" +
                    varBusinessTitle + "','" +
                    varFullCompanyName + "','" +
                    varURL + "','" +
                    varAddress + "','" +
                    varAddress2 + "','" +
                    varAddress3 + "','" +
                    varPostalCode + "','" +
                    varCity + "','" +
                    varState + "','" +
                    varCountry + "','" +
                    varMoblie + "','" +
                    varPhone + "','" +
                    varFax + "','" +
                    varEmail + "','" +
                    varRegistrationType + "','" +
                    varMemberShip + "','" +
                    varPassword + "','" +
                    varMemberShipID + "',#" +
                     System.DateTime.Now.ToString() + "#,'1','CreateUser')");
            }
            else
            {
                FOBTV.Web.MainClass.WebMessageBox.Show(this.Page, "该用户已存在!");
                return;
            }
            if (DBClassTmp.ExcuteSQL(sql, Conn))
            {
                FOBTV.Web.MainClass.WebMessageBox.Show(this.Page, "注册成功!!");
              
                info.CustomerID = strCustomerID;
                FOBTV.Web.MainClass.SessionState.CurrentUser = info;
               

                switch (FOBTV.Web.MainClass.SessionState.CurrentUser.Email)
                {
                    case "admin@fobtv2011.org":
                        Response.Redirect("CustomerList.aspx");
                        break;
                    
                    default:
                        Response.Redirect("RegistrationFee.aspx");
                         break;
               }
            }
            else
            {
                FOBTV.Web.MainClass.WebMessageBox.Show(this.Page, "操作失败!!");
            }
        }
    }
}